/*+ cache[([pref_mem] [ttl:n] [updatable])] [scope:(session|user|vdb)] */ sql ...
A query cache hint can be used to:
Indicate that a user query is eligible for result set caching and set the cache entry memory preference or time to live.
Set the materialized view memory preference, time to live, or updatablity.
Indicate that a virtual procedure should be cachable and set the cache entry memory preference or time to live.
/*+ cache[([pref_mem] [ttl:n] [updatable])] [scope:(session|user|vdb)] */ sql ...
The cache hint should appear at the beginning of the SQL. It will not have any affect on INSERT/UPDATE/DELETE statements or virtual update procedure definitions.
pref_mem- if present indicates that the cached results should prefer to remain in memory. They are not however required to be memory only.
Care should be taken to not over use the pref_mem option. The memory preference is implemented with Java soft references. While soft references are effective at preventing out of memory conditions. Too much memory held by soft references can limit the effective working memory. Consult your JVM options for clearing soft references if you need to tune their behavior.
ttl:n- if present n indicates the time to live value in milliseconds.
updatable- if present indicates that the cached results can be updated. This is currently only applicable to materialized views.
scope- if present indicates the override scope of query results. Using this flag, the user can override the computed scope. There are three different cache scopes: session - cached only for current session, user - cached for any session by the current user, vdb - cached for any user connected to the same vdb.
The form of the query hint must be matched exactly for the hint to have affect. For a user query if the hint is not specified correctly, e.g. /*+ cach(pref_mem) */, it will not be used by the engine nor will there be an informational log. As a workaround, the query plan may be checked though (see the Client Developers Guide) to see if the user command in the plan has retained the proper hint.
Individual queries may override the use of cached results by specifying OPTION NOCACHE on the query. 0 or more fully qualified view or procedure names may be specified to exclude using their cached results. If no names are specified, cached results will not be used transitively.
SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE
No cached results will be used at all.
SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE vg1, vg3
Only the vg1 and vg3 caches will be skipped, vg2 or any cached results nested under vg1 and vg3 will be used.
OPTION NOCACHE may be specified in procedure or view definitions. In that way, transformations can specify to always use real-time data obtained directly from sources.